<template>
  <div class="test-consultation-record">
    <h1>问诊记录模态框测试</h1>
    
    <div class="test-section">
      <h2>测试问诊记录弹出框</h2>
      <button @click="showTestModal" class="test-btn">显示问诊记录</button>
    </div>

    <!-- 问诊记录模态框 -->
    <div v-if="showRecordModal" class="modal-overlay" @click="closeRecordModal">
      <div class="modal-content" @click.stop>
        <div class="modal-header">
          <h3>{{ currentRecord.doctorName }}医生</h3>
          <button class="modal-close" @click="closeRecordModal">×</button>
        </div>
        <div class="modal-body">
          <div class="chat-container">
            <div 
              v-for="message in currentRecord.messages" 
              :key="message.id"
              :class="['message', message.type]"
            >
              <div class="message-avatar">
                <div class="avatar-placeholder">
                  {{ message.type === 'doctor' ? '👨‍⚕️' : '👤' }}
                </div>
              </div>
              <div class="message-content">
                <div class="message-text">{{ message.content }}</div>
                <div class="message-time">{{ message.time }}</div>
              </div>
            </div>
            <div class="consultation-end">
              {{ currentRecord.endTime }} 咨询结束
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue'

const showRecordModal = ref(false)
const currentRecord = ref({
  doctorName: '张三',
  endTime: '2020-04-05 10:40:20',
  messages: [
    {
      id: 1,
      type: 'patient' as const,
      content: '病症描述:最近四个月左膝盖总是隐隐的疼,特别是晚上,去医院检查说是轻度硬化,请问吃药需要多长时间能有改善?',
      time: '今天 10:20'
    },
    {
      id: 2,
      type: 'doctor' as const,
      content: '您好,您这种情况是由于平时过度劳累造成的损伤。',
      time: '10:25'
    },
    {
      id: 3,
      type: 'patient' as const,
      content: '请问我怎样做才能改善?',
      time: '10:30'
    },
    {
      id: 4,
      type: 'doctor' as const,
      content: '建议减少蹲下起来的活动,减少久站时间,少上下楼梯,然后平时多热敷,一般能自行恢复,平常补钙',
      time: '10:40'
    }
  ]
})

const showTestModal = () => {
  showRecordModal.value = true
}

const closeRecordModal = () => {
  showRecordModal.value = false
}
</script>

<style scoped>
.test-consultation-record {
  padding: 20px;
}

.test-section {
  margin-bottom: 30px;
  padding: 20px;
  border: 1px solid #ddd;
  border-radius: 8px;
}

.test-btn {
  padding: 10px 20px;
  background: #1890ff;
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
}

.test-btn:hover {
  background: #40a9ff;
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.modal-content {
  background: white;
  border-radius: 8px;
  width: 90%;
  max-width: 600px;
  max-height: 80vh;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #e9ecef;
  background: #f8f9fa;
}

.modal-header h3 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.modal-close {
  background: none;
  border: none;
  font-size: 24px;
  color: #666;
  cursor: pointer;
  padding: 0;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: all 0.3s;
}

.modal-close:hover {
  background: #e9ecef;
  color: #333;
}

.modal-body {
  padding: 0;
  max-height: calc(80vh - 80px);
  overflow-y: auto;
}

.chat-container {
  padding: 20px;
}

.message {
  display: flex;
  margin-bottom: 20px;
  gap: 12px;
}

.message.patient {
  flex-direction: row-reverse;
}

.message.doctor {
  flex-direction: row;
}

.message-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  overflow: hidden;
  flex-shrink: 0;
  background: #f0f0f0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.avatar-placeholder {
  font-size: 20px;
}

.message-content {
  flex: 1;
  max-width: 70%;
}

.message.patient .message-content {
  text-align: right;
}

.message-text {
  background: #f0f2f5;
  padding: 12px 16px;
  border-radius: 18px;
  font-size: 14px;
  line-height: 1.5;
  color: #333;
  word-wrap: break-word;
}

.message.doctor .message-text {
  background: #e6f7ff;
  color: #1890ff;
}

.message.patient .message-text {
  background: #f0f2f5;
  color: #333;
}

.message-time {
  font-size: 12px;
  color: #999;
  margin-top: 4px;
  padding: 0 4px;
}

.consultation-end {
  text-align: center;
  color: #999;
  font-size: 12px;
  margin-top: 30px;
  padding: 10px;
  border-top: 1px solid #f0f0f0;
}

@media (max-width: 768px) {
  .modal-content {
    width: 95%;
    max-height: 90vh;
  }
  
  .message-content {
    max-width: 85%;
  }
  
  .chat-container {
    padding: 15px;
  }
}
</style> 